<?php

namespace Admin\Controller;
//use Think\Controller;
use Tools\AdminController;
class AuthController extends AdminController{
    function showlist(){
          $auth_info = D('Auth')->order('auth_path')->select();

       $this->assign('auth_info',$auth_info);

        
        $this->display();
    }
    function tianjia(){
        $tianjia = new \Model\AuthModel();
        $info = $tianjia->where('auth_level=0')->select();
        $this->assign('info',$info);
        if(!empty($_POST)){
          $info = $tianjia->doadd($_POST);
          if($info){
              $this->redirect('showlist',array(),2,'添加权限成功!');
          }else{
              $this->redirect('tianjia',array(),2,'添加权限失败!');
          }
              
        } else {
            $this->display();    
        }
    }
    function  del($auth_id){
        if($auth_id){
            $info = D('Auth')->delete($auth_id);
            if($info){
                $this->redirect('showlist',array(),2,'删除成功!');
            }else{
                $this->redirect('showlist',array(),2,'删除失败!');
            }
        }
    }
    function xiugai($auth_id){
        $xiugai = new \Model\AuthModel();
        if(!empty($_POST)){
            $info = $xiugai->saveauth($_POST,$auth_id);
          if($info){
              $this->redirect('showlist',array(),2,'修改权限成功!');
          }else{
              $this->redirect('showlist',array(),2,'修改权限失败!');
          }
        }
        if($auth_id){
            $info = $xiugai->find($auth_id);
            $this->assign('info',$info);
            $auth_info = $xiugai->where('auth_level=0')->select();
            $this->assign('auth_info',$auth_info);
        }
        $this->display();
    }
}
